﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Principal;

namespace FinWeb3.DynamicData
{
    public class DynamicDataHelper
    {
        public static bool IsResultListAuthorized(object list, IIdentity user)
        {
            List<IDbEntity> entityList = new List<IDbEntity>();

            var bankList = list as List<dbBank>;
            var billList = list as List<dbBill>;
            var groupList = list as List<dbGroup>;
            var statementList = list as List<dbStatement>;

            if(bankList != null)
                foreach (var item in bankList)
                    entityList.Add(item);

            if (billList != null)
                foreach (var item in billList)
                    entityList.Add(item);

            if (groupList != null)
                foreach (var item in groupList)
                    entityList.Add(item);

            if (statementList != null)
                foreach (var item in statementList)
                    entityList.Add(item);

            return entityList.Count(x => x.UserName != user.Name) == 0;
        }
    }
}
